#include "StdAfx.h"
#include "Brute_Force.h"

CBrute_Force::CBrute_Force(void)
{
}

CBrute_Force::~CBrute_Force(void)
{
}
BOOL CBrute_Force::Init(LPDIRECT3DDEVICE9 pDevice)
{
	int iZ;
	int iX;
	CUSTOMVERTEX* g_Vertices=new CUSTOMVERTEX [m_iSize*m_iSize];
	if (!g_Vertices)
	{
		TRACE("New allocated-------------- failed\n");
		return FALSE;
	}
	CUSTOMVERTEX* tempg_Vertices=g_Vertices;
	for( iZ=0; iZ<m_iSize-1; iZ++ )
	{
		for( iX=0; iX<m_iSize-1; iX++ )
		{
			tempg_Vertices->x=iX;
			tempg_Vertices->y=GetScaledHeightAtPoint( iX, iZ );
			tempg_Vertices->z=iZ;
			tempg_Vertices->color=GetTrueHeightAtPoint( iX, iZ );
			++tempg_Vertices;
		}
	}
	HRESULT hr;
	VOID* pVertices=NULL;
	hr=pDevice->CreateVertexBuffer(sizeof(g_Vertices),0,D3DFVF_CUSTOMVETEX,D3DPOOL_DEFAULT,pVertexBuffer,NULL);
	if (FAILED(hr))
	{
		return FALSE;
	}
	hr=pVertexBuffer->Lock(0,sizeof(CUSTOMVERTEX),(VOID**)&pVertices,0);
	if (FAILED(hr))
	{
		return FALSE;
	}
	memcpy(pVertices,g_Vertices,m_iSize*m_iSize*sizeof(CUSTOMVERTEX));
	pVertexBuffer->Unlock();
	return TRUE;
}
VOID CBrute_Force::PreRender(LPDIRECT3DDEVICE9 pDevice)
{

}
VOID CBrute_Force::Render(LPDIRECT3DDEVICE9 pDevice)
{
	pDevice->BeginScene();
	pDevice->SetStreamSource(0,pVertexBuffer,0,sizeof(CUSTOMVERTEX));
	pDevice->SetFVF(D3DFVF_CUSTOMVETEX);
	pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,m_iSize*m_iSize-2);
	pDevice->EndScene();
}
VOID CBrute_Force::RenderEnd(LPDIRECT3DDEVICE9 pDevice)
{

}